{* $Id$ *}
{include_core file="admin/lib/header.html" title="评论展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">评论管理<span>在这里对评论进行管理</span></h2>
  </div>
  <div class="search-level1 clearfix">
    <form action="comment/admin" method="get">
      <input type="hidden" name="is_advenced" value="0">
      <input type="hidden" name="status" value="{$status}">
      <input {if $is_advenced == 1}style="display:none;"{/if} type="text" class="left" name="search_filter[title]" value="{$search_filter.title}">
      <button {if $is_advenced == 1}style="display:none;"{/if} type="submit" class="btn btn-success btn-sm left">搜索</button>
      {*<a href="javascript:void(0);" class="close js_advanced {if $is_advenced == 1}js_isOpen open{/if}">高级搜索<em></em></a>*}
    </form>
  </div>
  <div class="search-form js_advancedForm" {if $is_advenced == 0}style="display:none;"{/if}>
    {*<form action="comment/admin" method="get" class="js_commentSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">评论人：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_name]" value="{$search_filter.user_name}">
      </p>
      <p>
        <label for="" class="search-f-label">商品标题：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[goods_title]" value="{$search_filter.goods_title}">
      </p>
      <p>
        <label for="" class="search-f-label">评论内容：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[content]" value="{$search_filter.content}">
      </p>
      <p>
      <label for="" class="search-f-label">添加时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>*}
  </div>
  <!--start:列表-->
  <table class="list-table">
    <caption>按状态：
      <a href='{AnUrl("comment/admin?status=1")}' {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>正常</a>
      <a href='{AnUrl("comment/admin?status=0")}' {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已删除</a>
    </caption>
    <thead><tr>
      {if $status == 1}
      <th style="width:20px;"><input type="checkbox" class="selectAll"></th>
      {/if}
      <th>评论内容</th>
      <th style="width:100px;">评论人</th>
      <th style="width:130px;">添加时间</th>
      <th style="width:50px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $comment_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          {if $status == 1}
          <td><input type="checkbox" class="listSelect"></td>
          {/if}
          <td>
          {$goods_info = _uri('goods', $v.goods_id)}
            商品名称：{$goods_info.title}<br />
            评论内容：{$v.title}
          </td>
          <td>{user_helper::display_name($v.user_id)}</td>
          <td>{time_format($v.add_time)}</td>
          <td>
            {if $status == 1}
              <span style="display:none;" id="js_text_{$v.id}">{$smarty.const.SITE_URL}/{$module}/m/{$v.id}.html</span>
              <a href="javascript:void(0)" class="btn btn-success btn-xs js_comment" data-title="{$v.title}"><i class="icon-trash icon-white"></i>评论</a>
              <a href="{AnUrl("comment/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs deleteOne"><i class="icon-trash icon-white"></i>删除</a>
            {elseif $status == 0}
              <a href="{AnUrl("comment/admin/change_status?status=1")}" class="btn btn-success btn-xs changeStatus"><i class="icon-trash icon-white"></i>恢复</a>
            {/if}
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" class="selectAll"></td><td colspan="5"><a href="{AnUrl("comment/admin/delete")}" class="btn btn-danger btn-xs deleteAll">批量删除</a></td></tr></tfoot>
    {/if}
  </table>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
<script>
var resName = 'comment';
var jscommentId = "{$search_filter.comment_id}";
$('.js_commentId').load(siteUrl+'/comment/load_comment_option?res_name='+resName,function(){
  $('.js_commentId').find('option').each(function(){
    if ($(this).attr('value') == jscommentId) {
      $(this).attr('selected','selected');
    }
  });
});
$(function(){
  $('.js_comment').click(function(){
    var id = $(this).closest('tr').data('id');
    var title = $(this).data('title');
    var html = '';
    $.ajax({
      type: "POST",
      url: siteUrl+"/comment/admin/get_comment_children",
      data: { id:id },
      dataType: "json",
      async: false,
      cache: false,
      success: function(data){
        if (data) {
          html += '<table class="list-table" data-id="'+id+'">';
          for (var i in data) {
            html += '<tr data-id="'+data[i]['id']+'"><td>'+data[i]['title']+'</td><td width="50"><a href="javascript:void(0)" class="btn btn-success btn-xs js_edit"><i class="icon-trash icon-white"></i>编辑</a></td></tr>';
          }
          html += '<tr><td colspan="2"><a href="javascript:void(0)" class="btn btn-success btn-xs js_add"><i class="icon-trash icon-white"></i>新增评论</a></td></tr></table>'
        } else {
          html += '<table class="list-table" data-id="'+id+'"><tr><td><label>新增评论：<textarea class="js_text" style="resize: none;width:370px;;"></textarea></label></td><td><a href="javascript:void(0)" class="btn btn-success btn-xs js_right"><i class="icon-trash icon-white"></i>确认评论</a></td></tr><tr><td colspan="2"><a href="javascript:void(0)" class="btn btn-success btn-xs js_add"><i class="icon-trash icon-white"></i>新增评论</a></td></tr></table>';
        }
      }
    })
    ace.dialog({
      title: '评论管理',
      content:html,
      ok:function(){
        qDialog.close()
      },
      cancel:function(){
        return true;
      }
    });
  })
  
  $('.js_right').live('click', function(){
    var thisBtn = $(this);
    var commentId = thisBtn.closest('table').data('id');
    var val = thisBtn.closest('tr').find('.js_text').val();
    var id = thisBtn.closest('tr').data('id');
    
    if (!val) {
      showMsg('请填写要评论的内容');
      return false;
    }
    
    showConfirm('确认要添加么', 1, function(){
      $.ajax({
        type: "POST",
        url: siteUrl+"/comment/admin/add_comment",
        data: { value:val, comment_id:commentId, id:id },
        dataType: "json",
        async: false,
        cache: false,
        success: function(data){
          if (data) {
            var html = '<tr data-id="'+data.id+'"><td>'+data.title+'</td><td width="50"><a href="javascript:void(0)" class="btn btn-success btn-xs js_edit"><i class="icon-trash icon-white"></i>编辑</a></td></tr>';
            thisBtn.closest('tr').before(html);
            thisBtn.closest('tr').remove();
          }
        }
      })
    });
  })
  
  $('.js_add').live('click', function(){
    var html = '<tr><td><label>新增评论：<textarea class="js_text" style="resize: none;width:370px;;"></textarea></label></td><td><a href="javascript:void(0)" class="btn btn-success btn-xs js_right"><i class="icon-trash icon-white"></i>确认评论</a></td></tr>';
    $(this).closest('tr').before(html);
  })
  
  $('.js_edit').live('click', function(){
    var val = $(this).closest('tr').find('td').eq(0).html();
    var id = $(this).closest('tr').data('id');
    var html = '<tr data-id="'+id+'"><td><label>新增评论：<textarea class="js_text" style="resize: none;width:370px;;">'+val+'</textarea></label></td><td><a href="javascript:void(0)" class="btn btn-success btn-xs js_right" style="margin-right:5px;"><i class="icon-trash icon-white"></i>确认评论</a><a href="javascript:void(0)" class="btn btn-danger btn-xs js_del"><i class="icon-trash icon-white"></i>取消</a></td></tr>';
    $(this).closest('tr').before(html);
    $(this).closest('tr').hide();
  })
  
  $('.js_del').live('click', function(){
    $(this).closest('tr').next().show();
    $(this).closest('tr').remove();
  })
  
  // 高级搜索
  $('.js_advanced').click(function(e){
    e.preventDefault();
    var thisObj = $(this);
    var outBox  = thisObj.closest('form');
    if (thisObj.hasClass('js_isOpen')) {
      thisObj.removeClass('js_isOpen open');
      outBox.find('input').show();
      outBox.find('button').show();
      $('.js_advancedForm').hide();
    } else {
      thisObj.addClass('js_isOpen open');
      outBox.find('input').hide();
      outBox.find('button').hide();
      $('.js_advancedForm').show();
    }
  });
  
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });

  // 页面复制
  var clip = new ZeroClipboard( $('.js_copyList'), {
    moviePath: "../../../../js/zclip/ZeroClipboard.swf"
  });
  clip.on( 'complete', function(client, args) {
    showMsg("复制成功，复制内容为："+ args.text, 1);
  });
  
  // 查看预览效果
  $('.js_previewBtn').each(function(i){
    $(this).click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var resName = 'comment';
      var resId = thisObj.closest('tr').attr('data-id');
      
      showPreviewDialog(resName, resId);
    });
  });
});
</script>
{include_core file="admin/lib/footer.html"}